//
//  SwitchViewController.m
//  0222
//
//  Created by student on 16/2/22.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "SwitchViewController.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"

@interface SwitchViewController ()
@property (nonatomic,strong) FirstViewController *firstVC;
@property (nonatomic,strong) SecondViewController *secondVC;
@property (nonatomic,strong) ThirdViewController *thirdVC;



@end

@implementation SwitchViewController

- (FirstViewController *)firstVC
{
    if (_firstVC == nil)
    {
        _firstVC = [[FirstViewController alloc]init];
    }
    return _firstVC;
}

- (SecondViewController *)secondVC
{
    if (_secondVC == nil)
    {
        _secondVC = [[SecondViewController alloc]init];
    }
    return _secondVC;
}

- (ThirdViewController *)thirdVC
{
    if (_thirdVC == nil)
    {
        _thirdVC = [[ThirdViewController alloc]init];
    }
    return _thirdVC;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self switch:nil];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)switch:(id)sender {


    [UIView beginAnimations:@"ViewFlip" context:nil];
    [UIView setAnimationDuration:1.25];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    
        

        [self.view insertSubview:self.firstVC.view atIndex:0];
        [self.secondVC.view removeFromSuperview];
        [self.thirdVC.view removeFromSuperview];
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];

    
    [UIView commitAnimations];

}
- (IBAction)switchtosecond:(id)sender
{
    [UIView beginAnimations:@"ViewFlip" context:nil];
    [UIView setAnimationDuration:1.25];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

    [self.view insertSubview:self.secondVC.view atIndex:0];
    [self.firstVC.view removeFromSuperview];
    [self.thirdVC.view removeFromSuperview];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
    [UIView commitAnimations];
}
- (IBAction)switchtothird:(id)sender
{
    [UIView beginAnimations:@"ViewFlip" context:nil];
    [UIView setAnimationDuration:1.25];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

    [self.view insertSubview:self.thirdVC.view atIndex:0];
    [self.firstVC.view removeFromSuperview];
    [self.secondVC.view removeFromSuperview];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
    [UIView commitAnimations];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
